package edu.depaul.se.courseregistration.sessionbean;

import edu.depaul.se.courseregistration.jpa.user.Person;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
 *
 * @author Group2
 */
@Stateless
@LocalBean

public class PersonEJB {

    @PersistenceContext(unitName="CourseRegistrationModulePU")
    private EntityManager em;    
    
    //Person business APIs
    public List<Person> getAllUsers() {
        return em.createNamedQuery(Person.PERSON_QUERY_ALL).getResultList();
    }
    
    public Person findPersonById(int personID) {
        return em.createNamedQuery(Person.PERSON_QUERY_BY_ID, Person.class).
                setParameter("personID", personID).getSingleResult();
    }
        
   public Person findPersonByFirstName(String firstName) {
       return em.createNamedQuery(Person.PERSON_QUERY_BY_FIRSTNAME, Person.class).
               setParameter("firstName", firstName).getSingleResult();
    }    
        
    public Person findPersonByLastName(String lastName) {
        return em.createNamedQuery(Person.PERSON_QUERY_BY_LASTNAME, Person.class).
                    setParameter("lastName", lastName).getSingleResult();
    }
    
   public Person findPersonByEmail(String email) {
        return em.createNamedQuery(Person.PERSON_QUERY_BY_EMAIL, Person.class).
                    setParameter("email", email).getSingleResult();
    } 
    
  /* public Person findPersonByType(String userType) {
        return em.createNamedQuery(Person.PERSON_QUERY_BY_TYPE, Person.class).
                    setParameter("userType", userType).getSingleResult();
    }*/
 
}